from lib.webui_permission import *
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from hyrobot.common import CHECK_POINT, STEP


class c73312:
    name = '验证浏览器刷新功能-c73312'  # 测试用例名字

    # 初始化方法
    def setup(self):
        STEP(1, '登陆网站')
        driver = open_browser()
        user_login(driver)

    # 清除方法
    def teardown(self):
        driver = get_global_webdriver()
        driver.quit()

    # 测试用例步骤
    def teststeps(self):
        # 获取webdriver对象 对应 已经登录好的浏览器
        driver = get_global_webdriver()
        # driver = webdriver.Firefox()
        time.sleep(1)
        origin_product = driver.find_element(By.CSS_SELECTOR,
        '.el-card__body > ul:nth-child(2) > li:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > div:nth-child(4) > span:nth-child(1)'
                                              ).text
        STEP(2,"点击产品列表页签第二页")
        # time.sleep(1)
        page_button = driver.find_elements(By.CLASS_NAME,"number")
        time.sleep(1)
        page_button[1].click()
        time.sleep(1)
        expected_product = driver.find_element(By.CSS_SELECTOR,
        '.el-card__body > ul:nth-child(2) > li:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > div:nth-child(4) > span:nth-child(1)'
                                              ).text

        CHECK_POINT("检查是否翻页，两页的第一个不同", origin_product != expected_product)

        STEP(3,"点击刷新")
        driver.refresh()
        time.sleep(1)
        refreshed_got = driver.find_element(By.CSS_SELECTOR,
        '.el-card__body > ul:nth-child(2) > li:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > div:nth-child(4) > span:nth-child(1)'
                                               ).text
        CHECK_POINT("刷新后,第一个产品提示信息是否一致",
                    origin_product == refreshed_got)


